package com.zoffy.wmsbackend.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.zoffy.wmsbackend.common.BaseResponse;
import com.zoffy.wmsbackend.common.RequestParam;
import com.zoffy.wmsbackend.common.ResultUtils;
import com.zoffy.wmsbackend.model.dto.manufacturer.ManufacturerDTO;
import com.zoffy.wmsbackend.model.entity.Manufacturer;
import com.zoffy.wmsbackend.model.vo.ManufacturerVO;
import com.zoffy.wmsbackend.service.ManufacturerService;
import jakarta.annotation.Resource;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@PreAuthorize("hasAuthority('admin')")
@RequestMapping("/manufacturer")
public class ManufacturerController {
    @Resource
    private ManufacturerService manufacturerService;

    @PostMapping("/list")
    public BaseResponse<IPage<ManufacturerVO>> list(@RequestBody RequestParam<ManufacturerDTO> requestParam) {
        IPage<ManufacturerVO> res = manufacturerService.listManufacturerPage(requestParam);
        return ResultUtils.success(res);
    }

    @PostMapping("/listAll")
    public BaseResponse<List<Manufacturer>> listAll() {
        return ResultUtils.success(manufacturerService.list());
    }

    @PostMapping("/add")
    public BaseResponse<Boolean> addManufacturer(@RequestBody ManufacturerDTO dto) {
        Boolean res = manufacturerService.addManufacturer(dto);
        return ResultUtils.success(res);
    }
}